import random
import sys

from django.shortcuts import render

# Create your views here.
from rest_framework.renderers import JSONRenderer
from rest_framework.views import APIView


from wangming.utils.serializers import BaseSerializer
from wangming.utils.serializers import WangMing_TreeSearlizer
from shareAPI.views import APIResponse
from wangming import models
import logging

class Type(APIView):
    authentication_classes = []
    def get(self,request,*args,**kwargs):

        querySet = models.WangMing_Type.objects.all()

        if not querySet:
            return APIResponse(0, msg='数据库中没有内容')

        serResult = WangMing_TreeSearlizer.Tree_WangMing_Type_Seralizer(instance=querySet,many=True)

        return APIResponse(serResult.data)


#     空白名称字符串
class BlankName(APIView):
    print('BlankName')
    authentication_classes = []
    def post(self,request,*args,**kwargs):
        print(request.data)
        diyname = request.data.get('diyname')
        print(diyname)
        # A880 - A8DF  43208
        # a=chr(random.randint(43136,43231))
        # b=chr(random.randint(43136,43231))
        # c=chr(random.randint(43136,43231))  #10进制转16进制
        charsDict = ''
        '''2981,2982,2983,2987,2988,2989,3002,3003,3004,3005,3012,3013,3017,3027,3028,3029,3030,3032,3034,3033,3035,3036,3037,3038,3039,
        3040,3041,3042,3043,3044,3045,3069,3070,3071,3072,3076,3089,3113,3131,3132,3150,3151,3152,3153,3154,3155,3156,3165,3166,3167,3172,3173,3184,
        3185,3186,3187,3188,3189,3190,3191,3200,3201,3252,3258,3269,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069, 4070, 4071, 4072, 4073,
                    4074, 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4094, 4095,

                    4294, 4296, 4298, 4299, 4300, 4301, 4302, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885, 5886, 5887,5910, 5911,
                    5912, 5913, 5914, 5915, 5916, 5917, 5918, 5919,5973, 5974, 5975, 5976, 5977, 5978, 5979, 5980,
                    5981, 5982, 5983, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014,6316, 6317, 6318, 6319, 6390, 6391, 6392, 6393, 6394, 6395, 6396,
                    6397, 6398, 6399,6460, 6461, 6462, 6463,6794, 6795, 6796, 6797, 6798, 6799, 6847, 6848, 6849, 6850, 6851, 6852, 6853, 6854,
                     6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 6868, 6869, 6870, 6871, 6872, 6873, 6874, 
                     6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6894,
                      6895, 6896, 6897, 6898, 6899, 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6908, 6909, 6910,6911,7299, 7300, 7301, 7302,
                       7303,7304, 7305, 7306, 7307, 7308, 7309, 7310, 7311,7368, 7369, 7370, 7371, 7372, 7373, 7374, 7375,8433, 8434, 8435, 8436, 
                       8437, 8438, 8439, 8440, 8441, 8442, 8443, 8444, 8445, 8446, 8447'''
        listChar = [2981,2982,2983,2987,2988,2989,3002,3003,3004,3005,3012,3013,3017,3027,3028,3029,3030,3032,3034,3033,3035,3036,3037,3038,3039,
        3040,3041,3042,3043,3044,3045,3069,3070,3071,3072,3076,3089,3113,3131,3132,3150,3151,3152,3153,3154,3155,3156,3165,3166,3167,3172,3173,3184,
        3185,3186,3187,3188,3189,3190,3191,3200,3201,3252,3258,3269,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069, 4070, 4071, 4072, 4073,
                    4074, 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4094, 4095,

                    4294, 4296, 4298, 4299, 4300, 4301, 4302, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885, 5886, 5887,5910, 5911,
                    5912, 5913, 5914, 5915, 5916, 5917, 5918, 5919,5973, 5974, 5975, 5976, 5977, 5978, 5979, 5980,
                    5981, 5982, 5983, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014,6316, 6317, 6318, 6319, 6390, 6391, 6392, 6393, 6394, 6395, 6396,
                    6397, 6398, 6399,6460, 6461, 6462, 6463,6794, 6795, 6796, 6797, 6798, 6799, 6847, 6848, 6849, 6850, 6851, 6852, 6853, 6854,
                     6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 6868, 6869, 6870, 6871, 6872, 6873, 6874,
                     6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6894,
                      6895, 6896, 6897, 6898, 6899, 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6908, 6909, 6910,6911,7299, 7300, 7301, 7302,
                       7303,7304, 7305, 7306, 7307, 7308, 7309, 7310, 7311,7368, 7369, 7370, 7371, 7372, 7373, 7374, 7375,8433, 8434, 8435, 8436,
                       8437, 8438, 8439, 8440, 8441, 8442, 8443, 8444, 8445, 8446, 8447]




        charsDict =chr(random.choice(listChar))+chr(random.choice(listChar))+chr(random.choice(listChar))+chr(random.choice(listChar))+chr(random.choice(listChar))+chr(random.choice(listChar))
        return APIResponse(charsDict)
# 重命名模块
class ReName(APIView):
    print('ReName')
    authentication_classes = []
    def post(self,request,*args,**kwargs):
        diyname = request.data.get('diyname')
        print(diyname)
        listChar = [2981,2982,2983,2987,2988,2989,3002,3003,3004,3005,3012,3013,3017,3027,3028,3029,3030,3032,3034,3033,3035,3036,3037,3038,3039,
        3040,3041,3042,3043,3044,3045,3069,3070,3071,3072,3076,3089,3113,3131,3132,3150,3151,3152,3153,3154,3155,3156,3165,3166,3167,3172,3173,3184,
        3185,3186,3187,3188,3189,3190,3191,3200,3201,3252,3258,3269,4059,4060,4061,4062,4063,4064,4065,4066,4067,4068,4069, 4070, 4071, 4072, 4073,
                    4074, 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4094, 4095,

                    4294, 4296, 4298, 4299, 4300, 4301, 4302, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885, 5886, 5887,5910, 5911,
                    5912, 5913, 5914, 5915, 5916, 5917, 5918, 5919,5973, 5974, 5975, 5976, 5977, 5978, 5979, 5980,
                    5981, 5982, 5983, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014,6316, 6317, 6318, 6319, 6390, 6391, 6392, 6393, 6394, 6395, 6396,
                    6397, 6398, 6399,6460, 6461, 6462, 6463,6794, 6795, 6796, 6797, 6798, 6799, 6847, 6848, 6849, 6850, 6851, 6852, 6853, 6854,
                     6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 6868, 6869, 6870, 6871, 6872, 6873, 6874,
                     6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6894,
                      6895, 6896, 6897, 6898, 6899, 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6908, 6909, 6910,6911,7299, 7300, 7301, 7302,
                       7303,7304, 7305, 7306, 7307, 7308, 7309, 7310, 7311,7368, 7369, 7370, 7371, 7372, 7373, 7374, 7375,8433, 8434, 8435, 8436,
                       8437, 8438, 8439, 8440, 8441, 8442, 8443, 8444, 8445, 8446, 8447]


        b = ''
        for i in range(6 - len(diyname)):
            b = b + chr(random.choice(listChar))
        strlist = list(diyname)
        strlist.insert(random.randint(0, len(diyname)), b)


        query = models.WangMing_Score.objects.all().first()
        query.clickNum = query.clickNum+1
        query.save()
        #拼接LIST为字符串后输出
        return APIResponse("".join(strlist))